<?php

use app\assets\TableAsset;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\models\Api;
use app\models\Isp;
use app\models\KeyMap;
use app\models\PackageIsp;
use app\widgets\LinkPager;
use dosamigos\datepicker\DatePicker;

/**
 * @var $this yii\web\View
 * @var $apiList app\models\Api[]
 */

TableAsset::register($this);

$this->title = '订单列表';
$this->params['breadcrumbs'][] = '管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
    <div class="form-group">
        <a href="<?php echo Url::to(['/admin/storage/order-edit']);?>" class="btn btn-success btn-sm">添加</a>
    </div>
    <div class="form-group">
    <label for="search_order" class="sr-only">订单号</label>
    <?php echo Html::textInput('search_order', Yii::$app->request->get('search_order'), ['order' => 'search_order', 'class' => 'form-control', 'placeholder' => '订单号', 'style' => 'width: 120px;']);?>
    <label for="search_order" class="sr-only">项目名称</label>
    <?php echo Html::textInput('search_name', Yii::$app->request->get('search_name'), ['order' => 'search_order', 'class' => 'form-control', 'placeholder' => '项目名称', 'style' => 'width: 120px;']);?>
    <label for="rk_time">时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_time', 
        'options' => ['placeholder' => ''], 
        'attribute' => 'rk_time',
        'template' => '{addon}{input}',
        'value' => '',
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>

    </div>
    <div class="form-group">
    <label for="search_status" class="sr-only">状态</label>
    <?php echo Html::dropDownList('search_status', Yii::$app->request->get('search_status'), KeyMap::getValues('import_status'), ['id' => 'search_status', 'class' => 'form-control', 'prompt' => '导入状态']);?>
    </div>
    <div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
    <a href="<?php echo Url::current(['export'=>'excel']);?>">导出Excel</a>
    </div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th class="center">
                <label class="pos-rel">
                    <input type="checkbox" class="ace" />
                    <span class="lbl"></span>
                </label>
            </th>
            <th>订单号</th>
            <th>采购项目名称</th>
            <th>时间</th>
            <th>接口</th>
            <th>运营商</th>
            <th>套餐</th>
            <th>数量</th>
            <th>iccid开始</th>
            <th>iccid结束</th>
            <th>总价</th>
            <th>导入状态</th>
            <th>操作</th>
        </tr>
    </thead>

    <tbody>
        <?php foreach ($orderList as $list) {?>
            <tr>
                <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $list->id;?>" /><span class="lbl"><?php echo $list->id;?></span></label></td>
                <td><?php echo Html::encode($list->rkorder);?></td>
                <td><?php echo Html::encode($list->rk_name);?></td>
                <td><?php echo Yii::$app->formatter->asDate($list->rk_time);?></td>
                <td><?php echo Html::encode($list->api->name);?></td>
                <td><?php echo Html::a(Html::encode($list->isp->name), ['/admin/card/isp-view', 'id' => $list->isp_id]);?></td>
                <td><?php echo Html::a(Html::encode($list->packageIsp->name), ['/admin/card/package-view', 'id' => $list->package_id]);?></td>
                <td><?php echo Html::encode($list->number);?></td>
                <td><?php echo Html::encode($list->iccid_start);?></td>
                <td><?php echo Html::encode($list->iccid_end);?></td>
                <td><?php echo Html::encode($list->total_price);?></td>
                <td><?php echo KeyMap::getValue('import_status',$list->import_status);?></td>
                <td><?php echo ManagerTableOp::widget(['items' => [
                        ['icon' => 'fa fa-info-circle', 'href' => Url::to(['/admin/storage/order-view', 'id' => $list->id]), 'btn_class' => 'btn btn-xs btn-default', 'tip' => '详情'],
                        ['icon' => 'fa fa-pencil', 'href' => Url::to(['/admin/storage/order-modify', 'id' => $list->id]), 'btn_class' => 'btn btn-xs btn-success', 'tip' => '修改', 'color' => 'green'],
                        ['icon' => 'ace-icon fa fa-history bigger-12', 'href' => Url::to(['/admin/storage/order-import', 'id' => $list->id]), 'btn_class' => 'btn btn-xs btn-success', 'tip' => '导入', 'color' => 'green'],
                        ['icon' => 'fa fa-trash', 'onclick' => 'deleteOrder('.$list->id.')', 'btn_class' => 'btn btn-xs btn-danger','tip' => '删除', 'color'=>'red']
                    ]]);?></td>
            </tr>
        <?php }?>
    </tbody>
</table>
               
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
<script type="text/javascript">
    function deleteOrder(id) {
        if (!confirm('确定要删除此条入库订单吗？')) {
            return false;
        }
        $.getJSON('<?php echo Url::to(['/admin/storage/delete-order-list']);?>', {'id':id}, function(json) {
            if (callback(json)) {
                $('#data_' + id).remove();
            }
        });
    }
</script>